package cn.cas.mango.service;

import cn.cas.mango.config.NodeEntityRepository;
import cn.cas.mango.dto.param.neo4j.NodeEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Optional;

@Service
@Slf4j
public class Neo4jService {
  @Autowired
  private NodeEntityRepository repository;
  public NodeEntity createOrUpdateNode(NodeEntity node) {
    return repository.save(node);
  }

  public void createOrUpdateNode(Collection<NodeEntity> nodes) {
    repository.saveAll(nodes);
  }

//  public void addRelationship(String id, List<NodeEntity> relationships) {
//    Optional<NodeEntity> nodeOptional = repository.findById(id);
//    if (nodeOptional.isPresent()) {
//      NodeEntity node = nodeOptional.get();
//
//      for (NodeEntity relation: relationships) {
//        node.addRelationShip(relation);
//      }
//      repository.save(node);
//    }
//
//  }

  public void clearAll() {
    repository.deleteAll();
  }

  public void find(String id) {
    Optional<NodeEntity> nodeOptional = repository.findById(id);
    nodeOptional.ifPresent(System.out::println);
  }

}

